<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>


<div>
    <h1>年会抽奖</h1>
    <h1>获奖的手机号1：<span id="phone"></span></h1>
    <h1>获奖的手机号2：<span id="phone2"></span></h1>
</div>

<script>

    const tel = "15812345678"
    const reg = /^(\d{3})(\d{4})(\d{4})$/

    // 隐藏中间四位
    let str = tel.replace(reg, '$1****$3')
    document.getElementById('phone').innerText = str

    // 只显示后四位
    let str2 = tel.replace(reg,`${'*'.repeat(7)}$3`)
    document.getElementById('phone2').innerText = str2

</script>

</body>
</html>